<template>
  <leftLayout v-if="layout == 'left'" />
  <darkLayout v-else-if="layout == 'dark'" />
  <!-- ...更多布局方式 -->
</template>
<script>
import { app, cache,clearLogin } from "@/config";
import leftLayout from "@/layouts/left/Index";
import darkLayout from "@/layouts/dark/Index";
import { useRouter, useRoute, onBeforeRouteUpdate } from "vue-router";
// import { getMenuAuth } from "@/config/utils/permission";
import {
  reactive,
  toRefs,
} from "vue";
export default {
  components: {
    leftLayout,
    darkLayout,
  },
  setup() {
    const router = useRouter();
    const route = useRoute();
    const state = reactive({
      status:true
    })
    // 设置浏览器标题
    const setWebTitle = (to) => {
      document.title = to.meta.title
        ? app.name + "-" + to.meta.title
        : app.name;
    };

    // 验证登录
    const isLogin = () => {
        const adminUserInfo = cache("adminUserInfo")
        if (!adminUserInfo || !adminUserInfo["Authorization-Token"]) {
            clearLogin()
            // 跳转
            router.push({
                path: "/user/login",
            });
            return false
        }
        return true
    }
    isLogin()
    setWebTitle(route)
    // 动态监听路由变化，选中当前菜单
    onBeforeRouteUpdate((to) => {
      // 获取当前用户菜单权限
      // getMenuAuth()
      setWebTitle(to);
      isLogin(to);

    });
    return {
      layout: app.layouts.type,
      ...toRefs(state)
    };
  },
};
</script>